﻿'  __ _                 
' / _| |                
'| |_| |_   _ _ __ _ __ 
'|  _| | | | | '__| '__|
'| | | | |_| | |  | |   
'|_| |_|\__,_|_|  |_|

'Copyright (C) 2012, Rafal Marek Chmiel
'All rights reserved. http://flurr.codeplex.com/

'Copyright (C) 2010, Stephen Perelson (WinTumblr)
'All rights reserved. http://www.feedfeast.com/wintumblr/

' Redistribution and use in source and binary forms, with or without modification, are 
' permitted provided that the following conditions are met:
'
' - Redistributions of source code must retain the above copyright notice, this list 
'   of conditions and the following disclaimer.
' - Redistributions in binary form must reproduce the above copyright notice, this list 
'   of conditions and the following disclaimer in the documentation and/or other 
'   materials provided with the distribution.
'
' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
' ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
' WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
' IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
' INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
' NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
' PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
' WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
' ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
' POSSIBILITY OF SUCH DAMAGE.

Imports Flurr

Public Class mainForm

    Private tumblrData As tumblrAuth
    Dim acct As New tumblrAccount
    Dim textForm As New textForm(acct)
    'Dim photoForm As New tumblrPhotoPost(acct)
    'Dim quoteForm As New tumblrQuotePost(acct)
    'Dim linkForm As New tumblrLinkPost(acct)
    'Dim chatForm As New tumblrChatPost(acct)
    'Dim videoForm As New tumblrVideoPost(acct)

    Private Sub passwordForgetLinkLabel_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles passwordForgetLinkLabel.LinkClicked
        Process.Start("http://www.tumblr.com/forgot_password")
    End Sub

    Private Sub logInButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles logInButton.Click
        Me.Cursor = Cursors.WaitCursor
        logInButton.Enabled = False
        Dim account As New tumblrAccount
        tumblrData = New tumblrAuth()
        account.Email = emailTextBox.Text
        account.Password = passwordTextBox.Text
        If (account.Email.Length > 0) AndAlso (account.Password.Length > 0) Then
            Dim aA As New tumblrAuth.aAuthenticate(AddressOf tumblrData.authenticate)

            Dim result As IAsyncResult = aA.BeginInvoke(account, New AsyncCallback(AddressOf AuthCallbackMethod), aA)
        Else
            logInButton.Enabled = True
            Me.Cursor = Cursors.[Default]
            MessageBox.Show(Me, "Please check your email and/or password.", "Oops! Something went wrong.", MessageBoxButtons.OK, MessageBoxIcon.[Error])
        End If
    End Sub

    Private Sub AuthCallbackMethod(ByVal ar As IAsyncResult)
        If Me.InvokeRequired Then
            Me.BeginInvoke(New AsyncCallback(AddressOf AuthCallbackMethod), ar)
            Exit Sub
        End If
        Dim caller As Flurr.tumblrAuth.aAuthenticate = DirectCast(ar.AsyncState, tumblrAuth.aAuthenticate)
        Dim stat As tumblrStatus = caller.EndInvoke(ar)
        LogInButton.Enabled = True
        Me.Cursor = Cursors.[Default]
        If stat.code = tumblrStatus.codes.ok Then
            acct.email = emailTextBox.Text
            acct.password = passwordTextBox.Text
            MsgBox("Y") '"Y" will display if log in was successful
            newPostComboBox.Enabled = True
        Else
            MsgBox("N" & vbLf & vbLf & stat.message) '"N" will display if log in was unsuccessful and will show a reason why
        End If
    End Sub

    Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        newPostComboBox.SelectedIndex = 0
    End Sub

    Private Sub newPostComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles newPostComboBox.SelectedIndexChanged
        If newPostComboBox.SelectedIndex = 0 Then
            'Do Nothing
        ElseIf newPostComboBox.SelectedIndex = 1 Then
            textForm.ShowDialog()
        ElseIf newPostComboBox.SelectedIndex = 2 Then

        ElseIf newPostComboBox.SelectedIndex = 3 Then

        ElseIf newPostComboBox.SelectedIndex = 4 Then

        ElseIf newPostComboBox.SelectedIndex = 5 Then

        ElseIf newPostComboBox.SelectedIndex = 6 Then

        ElseIf newPostComboBox.SelectedIndex = 7 Then

        End If
    End Sub

End Class